/****************************************************************
 * Copyright (c) 2006-2007 Besture All Rights Reserved.
 * 
 * File Name:		MessageManager.cs
 * 
 * Created:		2013/06/24
 * Original Author:	Ni Tao
 * 
 * ------------------------------------------------------------
 * MODIFICATION HISTORY
 * ------------------------------------------------------------
 * When			Who		Why
 * ------------------------------------------------------------
 * 
 *
 ****************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Xml;

namespace Besture.Common.Definition
{
    public class MessageManager
    {

        public static Hashtable hashMessages = new Hashtable();

        public static void initialize()
        {

            string lsTmpElementName= "";
            String strFilePath = AppSettings.GetMessagePath();
            System.Xml.XmlTextReader loLoadSetting = new XmlTextReader(strFilePath);

            while (loLoadSetting.Read())
            {
                switch (loLoadSetting.NodeType)
                {
                    case XmlNodeType.Element:
                        lsTmpElementName = loLoadSetting.Name;
                        break;
                    case XmlNodeType.Text :
                        if (!lsTmpElementName.Equals(String.Empty))
                        {
                            hashMessages.Add(lsTmpElementName, loLoadSetting.Value);
                        }
                        break;
                }
            }

        }

        public static string GetMessage(string sID)
        {
            if (hashMessages[sID] != null)
            {
                return hashMessages[sID].ToString();
            }
            else
            {
                return String.Empty;
            }
        }

        public static string GetMessage(string sID, string[] sPara)
        {
            string lsMsg = "";
            string lsTmp = "";
            int li=0;
            lsMsg = hashMessages[sID].ToString();
            if (lsMsg != null)
            {
                foreach (string lsPara in sPara)
                {
                    lsTmp = "{" + li.ToString() + "}";
                    lsMsg=lsMsg.Replace(lsTmp, lsPara);
                    li++;
                }
                 
                return lsMsg ;
            }
            else
            {
                return String.Empty;
            }
        }
    }
}
